package org.realteam.hibernate.test.model;

import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.lang.StringUtils;
import org.realteam.hibernate.test.model.em.GenderEnum;
import org.springframework.beans.BeanUtils;


public class Event implements IEvent{
	
	private String id;
	
	private String title;
	
	private Date date;
	
	private GenderEnum  gender;

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public GenderEnum getGender() {
		return gender;
	}

	public void setGender(GenderEnum gender) {
		this.gender = gender;
	}
	
	@Override
	public String toString() {
		
		PropertyDescriptor[] descriptors = BeanUtils.getPropertyDescriptors(this.getClass());
		Object[] values = ArrayUtils.EMPTY_OBJECT_ARRAY;
		
		for (PropertyDescriptor descriptor : descriptors) {
			Method readMethod = descriptor.getReadMethod();
			
			try {
				Object value = readMethod.invoke(this, null);
				if (value instanceof String) 
					values = ArrayUtils.add(values, value);
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			}
		}
		
		return StringUtils.join(values, ",");
	}
}
